/**
 * @description 权限相关的接口
 * @author Elwin ZHANG
 * @date 2022-06-07 14:11
 */
import { useAxios } from '@/hooks/web/useAxios'

const request = useAxios()

/**
 * @description 获取当前用户菜单页面上按钮等权限
 * @author Elwin ZHANG
 * @date 2022-06-22 15:03
 */
export const getUserPageAuth = (menuId: string) => {
  return request.postXww({
    url: 'user/menu/getUserPageAuth',
    params: { menuId: menuId }
  })
}

/**
 * @description 获取当前公司所有可授权的菜单
 * @author Elwin ZHANG
 * @date 2022-06-07 15:04
 */
export const getAllMenus = () => {
  return request.postXww({
    url: 'user/menu/getAllMenus'
  })
}

/**
 * @description 删除公司的菜单
 * @param 菜单ID
 * @author Elwin ZHANG
 * @date 2023-03-30 10:27
 */
export const deleteMenu = (menuId: string) => {
  return request.postXww({
    url: 'user/menu/del',
    params: { pkId: menuId }
  })
}
/**
 * @description 获取某个菜单信息
 * @param 菜单ID
 * @author Elwin ZHANG
 * @date 2022-06-09 11:41
 */
export const getMenuById = (menuId: string) => {
  return request.postXww({
    url: 'user/menu/get',
    params: { pkId: menuId }
  })
}

/**
 * @description  获取某个菜单的可选择父菜单
 *  @param 菜单ID
 * @author Elwin ZHANG
 * @date 2023-04-03 11:56
 */
export const selectParentMenu = (menuId: string) => {
  return request.postXww({
    url: 'user/menu/selectParent',
    params: { pkId: menuId }
  })
}

/**
 * @description 保存菜单
 * @author Elwin ZHANG
 * @date 2022-06-09 13:41
 */
export const saveMenu = (data) => {
  return request.post({
    url: 'user/menu/saveMenu',
    data: data
  })
}

/**
 * @description 分页查詢公司或平台的用户组
 * @author Elwin ZHANG
 * @date 2022-06-07 15:04
 */
export const getGroups = (data) => {
  return request.post({
    url: 'user/group/query',
    data: data
  })
}

/**
 * @description 查询公司或平台的所有用户组
 * @author Elwin ZHANG
 * @date 2022-06-07 15:03
 */
export const getAllGroups = () => {
  return request.postXww({
    url: 'user/group/getAll'
  })
}

/**
 * @description 查詢单个用户组信息
 * @author Elwin ZHANG
 * @date 2022-06-07 15:03
 */
export const getGroupById = (groupId: string) => {
  return request.postXww({
    url: 'user/group/get',
    params: { pkId: groupId }
  })
}

/**
 * @description 查詢某个用户组可选择的父节点
 * @author Elwin ZHANG
 * @date 2023-03-07 15:03
 */
export const selectParentGroups = (groupId: string, groupType: number) => {
  return request.postXww({
    url: 'user/group/selectParentGroups',
    params: { groupId: groupId, groupType: groupType }
  })
}

/**
 * @description 删除用户组信息，
 * @param id ID
 * @author Elwin ZHANG
 * @date 2022-06-07 15:03
 */
export const deleteGroup = (id: string) => {
  return request.postXww({
    url: 'user/group/del',
    params: { id: id }
  })
}

/**
 * @description 保存用户组
 * @author Elwin ZHANG
 * @date 2022-06-07 15:03
 */
export const saveGroup = (data) => {
  return request.post({
    url: 'user/group/save',
    data: data
  })
}

/**
 * @description 获取用户组的授权信息
 * @author Elwin ZHANG
 * @date 2022-06-17 15:03
 */
export const getGroupAuthInfo = (groupId: string) => {
  return request.postXww({
    url: 'user/menu/getGroupAuthInfo',
    params: { groupId: groupId }
  })
}

/**
 * @description 保存用户组的授权信息
 * @author Elwin ZHANG
 * @date 2022-06-22 10:03
 */
export const saveGroupMenus = (data) => {
  return request.post({
    url: 'user/menu/editGroupMenus',
    data: data
  })
}
